module.exports = function ($scope, $resource, toaster, $modalInstance, $stateParams, FileUploader, $interval) {
    $scope.close = function(){
        $modalInstance.close();
    }
    $scope.info = {};
    $scope.canClick=false;  
    $scope.description = "获取验证码";  
    var second=59;  
    var timerHandler;  
    $scope.getTestCode = function(){  
        timerHandler = $interval(function(){  
            if(second<=0){  
                $interval.cancel(timerHandler);    //当执行的时间59s,结束时，取消定时器 ，cancle方法取消   
                second=59;  
                $scope.description="获取验证码";  
                $scope.canClick=false;    //因为 ng-disabled属于布尔值，设置按钮可以点击，可点击发送  
            }else{  
                $scope.description=second+"s后重发";  
                second--;  
                $scope.canClick=true;
            }  
        },1000)   //每一秒执行一次$interval定时器方法 
        // 发送验证码
        $resource('/api/ac/mc/merchantUserShopService/sendCode', {}, {}).save({}, function (res) {
            if (res.errcode === 0) {
              console.log(res);
              $scope.info.mobile = res.data.mobile;
            } else {
              // toaster.error({ title: '', body: res.errmsg });
              console.log('后台没有返回手机号,需要绑定手机号');
              var modalInstance = $modal.open({
                template: require('../../01dashboard/views/setPassword.html'),
                controller: 'setPassword',
                resolve: {
                  user: function () {
                    return '';
                  },
                  code: function () {
                    return '';
                  }
                }
              });
              modalInstance.result.then(function () {
              });
            }
        });
    };  

    // 验证手机号
    function checkMobile(str) {
        var re = /^1\d{10}$/
        if (re.test(str)) {
            alert("正确");
            return true;
        } else {
            alert("错误");
        }
    }
    // 解绑
    $scope.ok = function(){
        $resource('/api/ac/mc/merchantUserShopService/updatedel', {}, {}).save({'code' : $scope.info.code}, function (res) {
            if (res.errcode === 0) {
              console.log(res);
              toaster.success({ title: '', body: '解绑成功'});
              $modalInstance.close();
            } else {
              toaster.error({ title: '', body: res.errmsg });
            }
        });
    }
}  